{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 梯度下降算法模拟"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "plot_x = np.linspace(-1, 6, 141)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-1.  , -0.95, -0.9 , -0.85, -0.8 , -0.75, -0.7 , -0.65, -0.6 ,\n",
       "       -0.55, -0.5 , -0.45, -0.4 , -0.35, -0.3 , -0.25, -0.2 , -0.15,\n",
       "       -0.1 , -0.05,  0.  ,  0.05,  0.1 ,  0.15,  0.2 ,  0.25,  0.3 ,\n",
       "        0.35,  0.4 ,  0.45,  0.5 ,  0.55,  0.6 ,  0.65,  0.7 ,  0.75,\n",
       "        0.8 ,  0.85,  0.9 ,  0.95,  1.  ,  1.05,  1.1 ,  1.15,  1.2 ,\n",
       "        1.25,  1.3 ,  1.35,  1.4 ,  1.45,  1.5 ,  1.55,  1.6 ,  1.65,\n",
       "        1.7 ,  1.75,  1.8 ,  1.85,  1.9 ,  1.95,  2.  ,  2.05,  2.1 ,\n",
       "        2.15,  2.2 ,  2.25,  2.3 ,  2.35,  2.4 ,  2.45,  2.5 ,  2.55,\n",
       "        2.6 ,  2.65,  2.7 ,  2.75,  2.8 ,  2.85,  2.9 ,  2.95,  3.  ,\n",
       "        3.05,  3.1 ,  3.15,  3.2 ,  3.25,  3.3 ,  3.35,  3.4 ,  3.45,\n",
       "        3.5 ,  3.55,  3.6 ,  3.65,  3.7 ,  3.75,  3.8 ,  3.85,  3.9 ,\n",
       "        3.95,  4.  ,  4.05,  4.1 ,  4.15,  4.2 ,  4.25,  4.3 ,  4.35,\n",
       "        4.4 ,  4.45,  4.5 ,  4.55,  4.6 ,  4.65,  4.7 ,  4.75,  4.8 ,\n",
       "        4.85,  4.9 ,  4.95,  5.  ,  5.05,  5.1 ,  5.15,  5.2 ,  5.25,\n",
       "        5.3 ,  5.35,  5.4 ,  5.45,  5.5 ,  5.55,  5.6 ,  5.65,  5.7 ,\n",
       "        5.75,  5.8 ,  5.85,  5.9 ,  5.95,  6.  ])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plot_x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(141,)"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plot_x.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "plot_y = (plot_x - 2.5) ** 2 - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(141,)"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plot_y.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xl4ldW5/vHvkzmBJBAykJAREmYI\nYGRWQVAUUNRaxalqnap1qD+rx9r2dNaetp462zpTRVAQFRVHREVkCiBjAoSQOSQhQBIy7531+4Pg\noZY5O1l7e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Ed4hRMNsaM8ICti48DHxljBgKZdOLX2KMK3RiTY4zZbjvH\ncYwG8owx+caYFmA+MMtypmMyxnwF7LOd42QYY8qNMevb36/j0P8UfeymOjZzyMH2DwPb39x2wUpE\nEoEZwAu2s3gTEYkAzgZeBDDGtBhjDnTW9Tyq0D1AH6D4iI9LcOPS8VQikgqMBFbbTXJ87VMY3wKV\nwKfGGHfO+xjwANBmO8hJMsAnIrJORG61HeY4+gJVwMvt01kviEi3zrqY2xW6iHwmIluO8ua2I90j\nHO0Jwm47KvNEItIdeAv4mTGm1nae4zHGOI0xI4BEYLSIDLWd6WhEZCZQaYxZZzvLKZhgjBnFoenN\nn4rI2bYDHUMAMAp41hgzEqgHOm1tze0eEm2MmWo7QweUAElHfJwIlFnK4nVEJJBDZT7XGLPIdp6T\nZYw5ICJfcGi9wh0XoCcAF4vIdCAEiBCR14wx11rOdUzGmLL2HytF5G0OTXe649paCVByxL/OFtKJ\nhe52I3QPtxbIEJE0EQkCZgOLLWfyCiIiHJqHzDHG/K/tPCciIjEi0qP9/VBgKpBrN9XRGWN+YYxJ\nNMakcuh79nN3LnMR6SYi4YffB87HPf+ixBizBygWkQHtn5oCbOus63lUoYvIpSJSAowDPhCRj21n\nOpIxxgHcCXzMoUW7N40xW+2mOjYRmQesBAaISImI3GQ703FMAK4Dzm3fqvZt+4jSXcUDy0RkE4f+\nov/UGOP22wE9RBzwtYhsBNYAHxhjPrKc6XjuAua2fy+MAB7urAvpnaJKKeUlPGqErpRS6ti00JVS\nyktooSullJfQQldKKS+hha6UUl5CC10ppbyEFrpSSnkJLXSllPIS/x+DZnALDR7YeQAAAABJRU5E\nrkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x113445eb8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(plot_x, plot_y)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def dJ(theta):\n",
    "    return 2 * (theta - 2.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def J(theta):\n",
    "    return (theta - 2.5) ** 2 - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "eta = 0.1\n",
    "epsilon = 1e-8\n",
    "theta = 0.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "while True:\n",
    "    gradient = dJ(theta)\n",
    "    last_theta = theta\n",
    "    theta = theta - eta * gradient\n",
    "    \n",
    "    if (np.abs(J(theta) - J(last_theta)) < epsilon):\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.499891109642585"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "theta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.99999998814289"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "J(theta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "theta = 0\n",
    "eta = 0.1\n",
    "theta_history = [theta]\n",
    "while True:\n",
    "    gradient = dJ(theta)\n",
    "    last_theta = theta\n",
    "    theta = theta - eta * gradient\n",
    "    theta_history.append(theta)\n",
    "    if (np.abs(J(theta) - J(last_theta)) < epsilon):\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQA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bEGmPiqfmZ/c6Vy1xEGotIyLGPgUtxzb8oMcbs\nAzJFpFPtly4GttTX9dyq0EXkWhHJAgYAX4jI17YzHc8YUwk8AHxNzaLdh8aYzXZTnZqIfACsADqJ\nSJaI3GU702kMAm4FhtVuVVtfO6J0VVHAIhH5iZq/6L8xxrj8dkA30RJYJiIbgFXAF8aYryxnOp0H\ngRm1Pwu9gSfr60J6p6hSSnkItxqhK6WUOjUtdKWU8hBa6Eop5SG00JVSykNooSullIfQQldKKQ+h\nha6UUh5CC10ppTzE/wdJFkGExEMQDAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x113362940>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(plot_x, J(plot_x))\n",
    "plt.plot(np.array(theta_history), J(np.array(theta_history)), color = 'r', marker = '+')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "46"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(theta_history)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def plot_theta_history(theta_history):\n",
    "    plt.plot(plot_x, J(plot_x))\n",
    "    plt.plot(np.array(theta_history), J(np.array(theta_history)), color = 'r', marker = '+')\n",
    "    plt.show()\n",
    "        \n",
    "        \n",
    "def gradient_descent(initial_theta, eta, epsilon=1e-8, n_iters = 1e4):\n",
    "    theta = initial_theta\n",
    "    theta_history = [theta]\n",
    "    i_iter = 0\n",
    "    while i_iter < n_iters:\n",
    "        gradient = dJ(theta)\n",
    "        last_theta = theta\n",
    "        theta = theta - eta * gradient\n",
    "        theta_history.append(theta)\n",
    "\n",
    "        if (abs(J(theta) - J(last_theta)) < epsilon):\n",
    "            break\n",
    "        i_iter += 1\n",
    "        \n",
    "    plot_theta_history(theta_history)\n",
    "    print(\"len(theta_history) : \", len(theta_history))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def J(theta):\n",
    "    try:\n",
    "        return (theta - 2.5) ** 2 - 1\n",
    "    except:\n",
    "        return float(\"inf\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xl4VdW9PvD3m4EkkAnIQEISEghT\nGAIYmUUQLA6odWjFqWKttHWotl69tndQ7+3V/no7ONYWFeQKCkqtUidUJAFRhoRBhgQIITMZCGQg\nIcM5Z/3+SGIpJifDGdbe+7yf58lDcrLJfoX4ZrH22muLUgpERGR+froDEBGRe7DQiYgsgoVORGQR\nLHQiIotgoRMRWQQLnYjIIljoREQWwUInIrIIFjoRkUUEePNkUVFRKjk52ZunJCIyvZycnFNKqeie\njvNqoScnJyM7O9ubpyQiMj0RKerNcZxyISKyCBY6EZFFsNCJiCyChU5EZBEsdCIii2ChExFZBAud\niMgiTFHoH3x9Emt39moZJhGRoZTVnsNvPspDVUOzx89likL/8MBJ/G7TEbTY7LqjEBH1yfrdJfjL\n1uNotTk8fi5TFPrNFyfiTFMbNh2q1B2FiKjX7A6Ft7NLcMnoaCQMHujx85mi0OemRiFhcAjW7y7W\nHYWIqNe2Hq3Gybpm3HJxolfOZ4pC9/MT3JyRiO35NSiqadQdh4ioV97cVYyo0AFYOD7WK+czRaED\nwE0ZCfCT9vkoIiKjq6pvxua8Ktw4LQEDArxTtaYp9Li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nIFd3iD5YoJSaYoKli88C+FgpNQ5AOjz4Z2yqQldK5SqljujO4cR0APlKqQKlVCuAdQCu05ypW0qp\nrQBO687RG0qpk0qpPR3vN6D9f4rhelN1T7U72/FhYMebYS9YiUgCgKsBvKI7i5WISDiAeQBeBQCl\nVKtSqtZT5zNVoZvAcAAl531cCgOXjlmJSDKAqQB26k3iXMcUxj4AVQA+VUoZOe8zAB4F4OjpQINQ\nAD4RkRwRWa47jBMjAVQDWNUxnfWKiAzy1MkMV+gi8pmIHOzizbAj3fN09Ugcw47KzEhEQgH8FcBD\nSql63XmcUUrZlVJTACQAmC4iE3Vn6oqILAFQpZTK0Z2lD+YopaahfXrzPhGZpztQNwIATAPwklJq\nKoBGAB67tma4JxYppRbpzuCCUgCJ532cAKBcUxbLEZFAtJf5WqXUO7rz9JZSqlZEMtF+vcKIF6Dn\nALhWRK4CEAwgXETWKKVu15yrW0qp8o5fq0Tkb2if7jTitbVSAKXn/etsAzxY6IYboZvcbgCjRSRF\nRAYAWApgo+ZMliAigvZ5yFyl1B905+mJiESLSGTH+yEAFgHI05uqa0qpXyqlEpRSyWj/nv3cyGUu\nIoNEJKzzfQDfgTF/UEIpVQGgRETGdry0EMBhT53PVIUuIteLSCmAWQA+EJFNujOdTyllA3A/gE1o\nv2j3llLqkN5U3RORNwF8BWCsiJSKyN26MzkxB8AdAC7rWKq2r2NEaVRxALaIyNdo/0H/qVLK8MsB\nTSIWwBcish/ALgAfKKU+1pzJmQcArO34XpgC4ClPnYh3ihIRWYSpRuhERNQ9FjoRkUWw0ImILIKF\nTkRkESx0IiKLYKETEVkEC52IyCJY6EREFvH/AbCJalLcZb7dAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x113a10cf8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "len(theta_history) :  3682\n"
     ]
    }
   ],
   "source": [
    "eta = 0.001\n",
    "gradient_descent(0., eta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from LinearRegression import LinearRegression"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "reg_gd = LinearRegression()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "all the input arrays must have same number of dimensions",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-46-26307377af52>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mreg_gd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit_gd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mplot_x\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mplot_y\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/develop/study-machine-learning/LinearRegression.py\u001b[0m in \u001b[0;36mfit_gd\u001b[0;34m(self, X_train, y_train, eta, n_iters)\u001b[0m\n\u001b[1;32m     56\u001b[0m                         \u001b[0;32mreturn\u001b[0m \u001b[0mtheta\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     57\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 58\u001b[0;31m                 \u001b[0mX_b\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhstack\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mones\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_train\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mX_train\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     59\u001b[0m                 \u001b[0minitial_theta\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mzeros\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_b\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     60\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.6/site-packages/numpy/core/shape_base.py\u001b[0m in \u001b[0;36mhstack\u001b[0;34m(tup)\u001b[0m\n\u001b[1;32m    291\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0m_nx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconcatenate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marrs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    292\u001b[0m     \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 293\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0m_nx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconcatenate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marrs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    294\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    295\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mValueError\u001b[0m: all the input arrays must have same number of dimensions"
     ]
    }
   ],
   "source": [
    "reg_gd.fit_gd(plot_x, plot_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
